import 'babel-polyfill'
import Vue from 'vue'
import App from './App'
import axios from 'axios'
import Lockr from 'lockr'
import Cookies from 'js-cookie'
import _ from 'lodash'
import moment from 'moment'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import routes from './router/routes'
import VueRouter from 'vue-router'
import store from './vuex/store'
import filter from './assets/js/filter'
import _g from './assets/js/global'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import 'assets/css/global.css'
import 'assets/css/base.css'
import Icon from 'vue-svg-icon/Icon.vue'
import echarts from 'echarts'
import http from 'assets/js/http'
// import VueSocketio from 'vue-socket.io'  需要构筑即时通讯系统  将该项注释打开 并在app.vue中编辑相应代码
// http://pstsc.pstech360.com/
//axios.defaults.baseURL = 'http://pstsc.pstech360.com/api/'
axios.defaults.baseURL = 'http://192.168.0.233'
// axios.defaults.baseURL = 'http://yingdun.com/'
// axios.defaults.baseURL = axios.defaults.baseUR
axios.defaults.timeout = 1000 * 15
axios.defaults.headers.authKey = Lockr.get('authKey')
axios.defaults.headers.sessionId = Lockr.get('sessionId')
axios.defaults.headers['Content-Type'] = 'application/json'
axios.defaults.withCredentials = true
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'
Vue.prototype.$echarts = echarts
const router = new VueRouter({
	mode: 'history',
	base: __dirname,
	routes
})
let whiteList = ['/cms/login']
router.beforeEach((to, from, next) => {
	console.log('to', to)
	console.log('next', next)
	console.log('from', from)
	let index = whiteList.indexOf(to.path)
	if(index = -1) {
		//不是白名单中，判断时候登录
		axios.post('/AdminApi/SystemSetting/admin_set').then((response) => {
			console.log('response', response)
			if(response.data.data) {
				//返回不为空，说明登录了
				next()
			} else {
				next('/cms/login')
			}
		}).catch((response) => {
			console.log('response1', response1)

			//        bus.$message({
			//          message: '请求超时，请检查网络',
			////          type: 'warning'
			//        })
		})
	}
	console.log('to.meta.hideLeft', to)
	const hideLeft = to.meta.hideLeft
	store.dispatch('showLeftMenu', hideLeft)
	store.dispatch('showLoading', true)
	//NProgress.start()
	next()
})

router.afterEach(transition => {
	NProgress.done()
})

Vue.use(ElementUI)
Vue.use(VueRouter)
// Vue.use(VueSocketio, 'http://szt.pstech360.com:2021')
Vue.component('icon', Icon)

window.router = router
window.store = store
window.HOST = HOST
//window.ResourceBaseUrl = 'http://pstsc.pstech360.com/'
window.ResourceBaseUrl = 'http://192.168.0.233/'
window.axios = axios
window._ = _
window.moment = moment
window.Lockr = Lockr
window.Cookies = Cookies
window._g = _g
window.pageSize = 15

const bus = new Vue()
window.bus = bus

new Vue({
	el: '#app',
	template: '<App/>',
	filters: filter,
	router,
	store,
	components: {
		App
	}
	// render: h => h(Login)
}).$mount('#app')